/**
 *  @作者：stranger.lin
 *  @时间：2012/5/19
 * 
 * 
 **/
if(typeof(UI)=="undefined")UI={};
UI.msg={};
UI.dlg={};
UI.message={};
/**
 *  ERROR dlg
 * 
 **/
UI.dlg.error=function(content){
	$("#msgHTML").html("<table align=\"center\"><tr><td width=\"20%\" align=\"center\"><img src=\"images/alert/error.gif\" border=\"0\" /></td>" +
	"<td align=\"center\" width=\"80%\" style=\"font-weight: bolder;font-size:16px;\">"+content+"</td></tr></table>");
	showMsg();

}
/**
 *  info dlg
 * 
 **/
UI.dlg.info=function(content){
	$("#msgHTML").html("<table align=\"center\"><tr><td width=\"20%\" align=\"center\"><img src=\"images/alert/message.gif\" border=\"0\" /></td>" +
	"<td align=\"right\" width=\"80%\" style=\"font-weight: bolder;font-size:16px;\">"+content+"</td></tr></table>");
	showMsg();
}

/**
 *  ok dlg
 * 
 **/
UI.dlg.ok=function(content){
	$("#msgHTML").html("<table align=\"center\"><tr><td width=\"20%\" align=\"center\"><img src=\"images/alert/ok.gif\" border=\"0\" /></td>" +
	"<td align=\"right\" width=\"80%\" style=\"font-weight: bolder;font-size:16px;\">"+content+"</td></tr></table>");
	showMsg();
}

UI.msg.info=function(content){
	showMsg(content);
}

function showLoading(temp){
	if(temp==1){
		document.getElementById("UIloading").style.width=document.body.scrollWidth+"px";
        document.getElementById("UIloading").style.height=document.body.scrollHeight+"px";
        document.getElementById("UIloading").style.display="block";
	}else if(temp==0){
		document.getElementById("loading").style.display="none";
	}
}

UI.ajaxSubmit=function(options){
	if(!options)options={};
	if(!options.url) return false;
	if(!options.type) options.type = "POST";
	if(!options.dataType)options.dataType="json"
	if(!options.success){
		options.success=function(message){
			if(message.type=="SUCCESS"){
				UI.dlg.ok(message.msg);
			}else if(message.type=="ERROR"){
				UI.dlg.error(message.msg);
			}
		}
	}
	
	$.ajax({
		url:options.url,
		type:options.type,
		data:options.data,
		dataType:options.dataType,
		success:function(message){
			options.success(message);
		}
	});

	return true;
	
}
UI.message.show=function(timer){
	if(typeof(timer)=="undefined")timer=500;
	if(document.getElementById("ui_message").style.display=="block"){
		messageHide(timer);
	}else{
		messageShow(timer);
	}
	

}

function messageShow(timer){
	 document.getElementById("ui_message").style.display="block";	 
	 var height=document.getElementById("ui_message").style.height;
	 height=parseInt(height);
	 height=height+5;
	 document.getElementById("ui_message").style.height=height+"px";
	
	 var _timer=setTimeout("messageShow('"+timer+"')",timer);
	if(height>=100){
		
		clearTimeout(_timer);
		return;
	}
	
}

function messageHide(timer){
	 
	 var height=document.getElementById("ui_message").style.height;
	 height=parseInt(height);
	 height=height-5;
	 document.getElementById("ui_message").style.height=height+"px";
	
	 var _timer=setTimeout("messageHide('"+timer+"')",timer);
	 if(height<=0){
		
		clearTimeout(_timer);
		 document.getElementById("ui_message").style.display="none";	
		return;
	 }
	
}

$(function(){
	var msgHtml="<div id=\"ui_message\" style=\" background-color: #E5F0F8; display:none;overflow:hidden; width: 250px;height: 0px;position:absolute; right:5px; bottom:5px;\">"+
                "<table border=\"1\" cellpadding=\"0\"  cellspacing=\"0\" width=\"95%\"style=\"border-color:#62BBE8; height:85%;margin: 10px 10px 10px 10px;\">"+
	            "<tr><td align=\"right\" style=\"border-right: none;\"><img width=\"50\" style=\"height: 40px;\" src=\"images/email.png\" border=\"0\"></td> <td align=\"left\" style=\"border-left: none;\">你有新的短消息</td></tr></table>"
                "</div>";
	$("body").append(msgHtml);
	$("#ui_message").addClass("ui-corner-all");
	
	$("input:button")==null?"":$("input:button").button();
	$("input:submit")==null?"":$("input:submit").button();
	
});
